package org.liangliang.iching;

import java.util.ArrayList;
import java.util.List;

public class Gua {
    private String name;
    private List<Yao> yaoList;

    private int no;

    public int getNo() {
        return no;
    }

    public void setNo(int no) {
        this.no = no;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<Yao> getYaoList() {
        return yaoList;
    }

    public void setYaoList(List<Yao> yaoList) {
        this.yaoList = yaoList;
    }

    public static Gua create(String name,int yaoSymbol1,int yaoSymbol2,int yaoSymbol3,
                             int yaoSymbol4,int yaoSymbol5,int yaoSymbol6){
        Gua gua = new Gua();
        gua.setName(name);
        createYaoList(yaoSymbol1, yaoSymbol2, yaoSymbol3, yaoSymbol4, yaoSymbol5, yaoSymbol6, gua);
        return gua;

    }

    public static Gua create(String name,String yaoSymbolStr){
        Gua gua = new Gua();
        gua.setName(name);
       createYaoList2(yaoSymbolStr,gua);
        return gua;

    }

    private static void createYaoList(int yaoSymbol1, int yaoSymbol2, int yaoSymbol3, int yaoSymbol4, int yaoSymbol5, int yaoSymbol6, Gua gua) {
        gua.yaoList=new ArrayList<>();
        gua.yaoList.add(Yao.create(yaoSymbol1));
        gua.yaoList.add(Yao.create(yaoSymbol2));
        gua.yaoList.add(Yao.create(yaoSymbol3));
        gua.yaoList.add(Yao.create(yaoSymbol4));
        gua.yaoList.add(Yao.create(yaoSymbol5));
        gua.yaoList.add(Yao.create(yaoSymbol6));
    }

    private static void createYaoList2(String yaoSymbolStr, Gua gua) {
        String[] split = yaoSymbolStr.split("");
        gua.yaoList=new ArrayList<>();
        for (int i = 0; i < split.length; i++) {
            gua.yaoList.add(Yao.create(Integer.parseInt(split[i])));
        }
    }


    public static List<Gua> initGuaList() {
        List<Gua> guaList=new ArrayList<>();
        guaList.add(Gua.create("乾",1,1,1,1,1,1));
        guaList.add(Gua.create("坤",0,0,0,0,0,0));
        guaList.add(Gua.create("屯",1,0,0,0,1,0));
        guaList.add(Gua.create("蒙",0,1,0,0,0,1));
        guaList.add(Gua.create("需",1,1,1,0,1,0));
        guaList.add(Gua.create("讼",0,1,0,1,1,1));
        guaList.add(Gua.create("师",0,1,0,0,0,0));
        guaList.add(Gua.create("比","000010"));
        guaList.add(Gua.create("小畜","111011"));
        guaList.add(Gua.create("履","110111"));
        guaList.add(Gua.create("泰","111000"));
        guaList.add(Gua.create("否","000111"));
        guaList.add(Gua.create("同人","101111"));
        guaList.add(Gua.create("大有","111101"));
        guaList.add(Gua.create("谦","001000"));
        guaList.add(Gua.create("豫","000100"));
        guaList.add(Gua.create("随","100110"));
        guaList.add(Gua.create("蛊","011001"));
        guaList.add(Gua.create("临","110000"));
        guaList.add(Gua.create("观","000011"));
        guaList.add(Gua.create("噬嗑","100101"));
        guaList.add(Gua.create("贲","101001"));
        guaList.add(Gua.create("剥","000001"));
        guaList.add(Gua.create("复","100000"));
        guaList.add(Gua.create("无妄","100111"));
        guaList.add(Gua.create("大畜","111001"));
        guaList.add(Gua.create("颐","100001"));
        guaList.add(Gua.create("大过","011110"));
        guaList.add(Gua.create("坎","010010"));
        guaList.add(Gua.create("离","101101"));
        guaList.add(Gua.create("咸","001110"));
        guaList.add(Gua.create("恒","011100"));
        guaList.add(Gua.create("遁","001111"));
        guaList.add(Gua.create("大壮","111100"));
        guaList.add(Gua.create("晋","000101"));
        guaList.add(Gua.create("明夷","101000"));
        guaList.add(Gua.create("家人","101011"));
        guaList.add(Gua.create("睽","110101"));
        guaList.add(Gua.create("蹇","001010"));
        guaList.add(Gua.create("解","010100"));
        guaList.add(Gua.create("损","110001"));
        guaList.add(Gua.create("益","100011"));
        guaList.add(Gua.create("夬","111110"));
        guaList.add(Gua.create("姤","011111"));
        guaList.add(Gua.create("萃","000110"));
        guaList.add(Gua.create("升","011000"));
        guaList.add(Gua.create("困","010110"));
        guaList.add(Gua.create("井","011010"));
        guaList.add(Gua.create("革","101110"));
        guaList.add(Gua.create("鼎","011101"));
        guaList.add(Gua.create("震","100100"));
        guaList.add(Gua.create("艮","001001"));
        guaList.add(Gua.create("渐","001011"));
        guaList.add(Gua.create("归妹","110100"));
        guaList.add(Gua.create("丰","101100"));
        guaList.add(Gua.create("旅","001101"));
        guaList.add(Gua.create("巽","011011"));
        guaList.add(Gua.create("兑","110110"));
        guaList.add(Gua.create("涣","010011"));
        guaList.add(Gua.create("节","110010"));
        guaList.add(Gua.create("中孚","110011"));
        guaList.add(Gua.create("小过","001100"));
        guaList.add(Gua.create("既济","101010"));
        guaList.add(Gua.create("未济","010101"));
        listSetNo(guaList);
        return guaList;
    }

    private static void listSetNo(List<Gua> guaList) {
        for (int i = 0; i < guaList.size(); i++) {
            guaList.get(i).setNo(i+1);
        }
    }

    public static List<Gua> initXianTianGuaList() {
        List<Gua> guaList=new ArrayList<>();
        guaList.add(Gua.create("乾","111"));
        guaList.add(Gua.create("兑","110"));
        guaList.add(Gua.create("离","101"));
        guaList.add(Gua.create("震","100"));
        guaList.add(Gua.create("巽","011"));
        guaList.add(Gua.create("坎","010"));
        guaList.add(Gua.create("艮","001"));
        guaList.add(Gua.create("坤","000"));
        listSetNo(guaList);
        return guaList;
    }

    public String createIndex(){
        String index="";
        for (Yao yao : getYaoList()) {
            index+=yao.getSymbol();
        }
        return index;
    }

}
